package cn.changeforyou.tcpIp.analysis.demo;

import cn.changeforyou.tcpIp.analysis.demo.protocol.gbt32960_3.BusUploadProtocol;
import cn.changeforyou.tcpIp.analysis.demo.protocol.gbt32960_3.handler.RealtimeInfoUploadHandler;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ServerHandler extends ChannelInboundHandlerAdapter {

    RealtimeInfoUploadHandler handler = new RealtimeInfoUploadHandler();

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        BusUploadProtocol protocol = (BusUploadProtocol) msg;
        handler.analysis(protocol);
        System.out.println(protocol);
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) {
        ctx.writeAndFlush(Unpooled.EMPTY_BUFFER);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx,
        Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}